home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / PrinterClassDriver / MissingLibraryRoutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  3.7 KB  |  104 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MissingLibraryRoutines.c
  3.  
  4.     Contains:    Implementation of routines missing from InterfaceLib.
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.  
  9.  
  10.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  11.  
  12. */
  13.  
  14. /*
  15.     You may incorporate this sample code into your applications without
  16.     restriction, though the sample code has been provided "AS IS" and the
  17.     responsibility for its operation is 100% yours.  However, what you are
  18.     not permitted to do is to redistribute the source as "DSC Sample Code"
  19.     after having made changes. If you're going to re-distribute the source,
  20.     we require that you make it clear in the source that the code was
  21.     descended from Apple Sample Code, but that you've made changes.
  22. */
  23.  
  24. #include <Types.h>
  25. #ifndef __MIXEDMODE__
  26. #include <mixedmode.h>
  27. #endif
  28. #ifndef __DEVICES__
  29. #include <devices.h>
  30. #endif
  31.  
  32. // This file contains implementations of various Mac OS API routines
  33. // that were never rolled in to InterfaceLib.  As a result, these
  34. // routines can be called from classic 68K clients, but not from
  35. // CFM-68K or CFM-PPC clients.
  36.  
  37. extern pascal SInt16 LMGetUnitTableEntryCount(void);
  38. extern pascal void LMSetUnitTableEntryCount(SInt16 value);
  39.  
  40. extern pascal SInt16 LMGetUnitTableEntryCount(void)
  41.     // Get the value from low memory directly.
  42. {
  43.     return *((SInt16 *) 0x01d2);
  44. }
  45.  
  46. extern pascal void LMSetUnitTableEntryCount(SInt16 value)
  47.     // Put the value into low memory directly.
  48. {
  49.     *((SInt16 *) 0x01d2) = value;
  50. }
  51.  
  52. // DriverInstallReserveMem is a bit trickier to implement that the
  53. // previous two routines.  Basically we have get the address of the
  54. // _DriverInstall ($A03D) trap and then call it using
  55. // CallOSTrapUniversalProc.  There are a number of important things
  56. // to note here:
  57. //   a) We can just get the trap address and treat it as a UPP.
  58. //      The trap tables are defined to contain UPPs, either pointers
  59. //      to real 68K code, or pointers to a routine descriptor (if
  60. //      the trap is native or fat).
  61. //   b) We must use CallOSTrapUniversalProc, not CallUniversalProc.
  62. //      CallOSTrapUniversalProc automatically does a number of things 
  63. //      that are very critical for call OS traps.  See "IM:PowerPC
  64. //      System Software", p2-42 for a full description.
  65. //   c) When calling OS traps from PPC, it's important to get the
  66. //      ProcInfo right.  Specifically, all OS traps assume an
  67. //      implicit parameter of D1 as the first parameter.  After
  68. //      that, the parameters should be defined in the order that
  69. //      they are declared in the prototype.  If you fail to get
  70. //      the order right, or to put D1 first, your code will work,
  71. //      up until it encounters someone who has patched the OS trap
  72. //      with a native or fat patch.  Then strange things will happen,
  73. //      and you'll spend hours in MacsBug trying to figure it out.
  74.  
  75. // The trap number and ProcInfo description for DriverInstallReserveMem.
  76.  
  77. enum {
  78.     _DriverInstallReserveMem = 0x0A43D
  79. };
  80.  
  81. enum {
  82.     uppDriverInstallProcInfo = kRegisterBased
  83.         | REGISTER_RESULT_LOCATION(kRegisterD0)
  84.         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  85.         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(short)))
  86.         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(DRVRHeaderPtr)))
  87.         | REGISTER_ROUTINE_PARAMETER(3, kRegisterD0, SIZE_CODE(sizeof(short)))
  88. };
  89.  
  90. extern pascal OSErr DriverInstallReserveMem(DRVRHeaderPtr drvrPtr, short refNum)
  91. {
  92.     UniversalProcPtr trapAddress;
  93.     
  94.     // Check that I've got the ProcInfo correct.
  95.     if (false) {
  96.         if ( uppDriverInstallProcInfo != 0x00533022) {
  97.             DebugStr("\pDriverInstallReserveMem: uppDriverInstallProcInfo is not what it should be.");
  98.         }
  99.     }
  100.     
  101.     trapAddress = (UniversalProcPtr) GetOSTrapAddress(_DriverInstallReserveMem);
  102.     return CallOSTrapUniversalProc(trapAddress, uppDriverInstallProcInfo, _DriverInstallReserveMem, drvrPtr, refNum);
  103. }
  104.